package com.controller.admin.user;

import com.entity.Company;
import com.entity.User;
import com.service.AdminService;
import com.service.impl.AdminServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddUser")
public class AddUser  extends HttpServlet {
    AdminService adminService=new AdminServiceimpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String userId = req.getParameter("userId");
        String name = req.getParameter("name");
        String pwd = req.getParameter("pwd");
        String realName= req.getParameter("realName");
        String uSex = req.getParameter("uSex");
        String age = req.getParameter("age");
        String school = req.getParameter("school");
        String state = req.getParameter("state");
        String xueLi = req.getParameter("xueLi");
        String cardNum = req.getParameter("cardNum");
        String major = req.getParameter("major");
        String photo = req.getParameter("photo");
        String tel = req.getParameter("tel");
        System.out.println("pwd = " + pwd);

        System.out.println("state = " + state);

        User user = new User();
        user.setUserId(userId);
        user.setName(name);
        user.setPwd(pwd);
        user.setRealName(realName);
        user.setuSex(uSex);
        user.setAge(age);
        user.setSchool(school);
        user.setState(state);
        user.setXueLi(xueLi);
        user.setCardNum(cardNum);
        user.setMajor(major);
        user.setPhoto(photo);
        user.setTel(tel);
        System.out.println("adduser = " + user);
//        int addi1 = adminService.AddCompany(company);
        int addi = adminService.AddUser(user);
        System.out.println("adduseri = " + addi);
        if(addi==1){
            resp.getWriter().write("success");
        }else{
            System.out.println(" error" );
            resp.getWriter().write("error");
        }
    }
}
